<template>
	<view>
		<view class="img">
			<image @click="xz" :src="user.img" mode=""></image>
			<view>点击更换头像</view>
		</view>
		<view class="content_abx">
			<view>姓名</view>
			<input type="text" v-model='user.guanli_hymc'>
		</view>
		<view class="content_abx">
			<view>电话号码</view>
			<input type="text" v-model='newsjhm'>
		</view>
		<view class="bz">
			<textarea v-model="user.msg"></textarea>
		</view>
		<view class="tj">
			<button @click="bc">保存</button>
		</view>
	</view>
</template>

<script>
	import { reactive,toRefs} from 'vue'
	import http from '../../../utils/http.js'
	import store from '../../../store/index.js'
	export default {
		setup(){
			let data=reactive({
				user:{},
				newsjhm:'',
				back:()=>{
					uni.navigateBack({
						delta:1
					})
				},
				xz:()=>{
					uni.chooseImage({
						count: 1,
						sourceType: ['album'],
						success: function (res) {
							var tempFilePaths = res.tempFilePaths;
							    uni.saveFile({
							      tempFilePath: tempFilePaths[0],
							      success: function (res) {
							        var savedFilePath = res.savedFilePath;
									http({
										url:'/users/imgup',
										method:'post',
										data:{
											phone:store.getters.getUser.guanli_sjhm,
											img:savedFilePath
										}
									}).then((e)=>{
										uni.removeSavedFile({
										    filePath: data.user.img,
										    complete: function (res) {
										      console.log(res);
										    }    
										});
										data.user.img=savedFilePath
									})
							      }
							});
						}
					});
				},
				bc:()=>{
					http({
						url:'/users/userSet',
						method:'post',
						data:{
							phone:data.user.guanli_sjhm,
							name:data.user.guanli_hymc,
							newphone:data.newsjhm,
							msg:data.user.msg
						}
					}).then((e)=>{
						http({
							url:'/users/login',
							method:'post',
							data:{phone:data.newsjhm}
						}).then((e)=>{
							store.commit('setUser',e.data.data[0])
						})
						wx.showToast({
						  title: '保存成功',
						  icon:'success',
						  duration: 2000
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},2000)
					})
				}
			})
			return {...toRefs(data)}
		},
		onShow(){
			this.user=store.getters.getUser
			this.newsjhm=this.user.guanli_sjhm
			this.user.img=this.user.img==''?'../../../static/logo.png':this.user.img
		}
	}
</script>

<style scoped lang="less">

.img{
	text-align: center;
	font-size: 25rpx;
	padding: 30rpx 0;
	image{
		width: 150rpx;
		height: 150rpx;
	}
}
.content_abx{
	display: flex;
	line-height: 80rpx;
	height: 80rpx;
	border-top: 1px solid #d9d9d9;
	input{
		height: 80rpx;
	}
	view{
		width: 130rpx;
		padding: 0 50rpx;
	}
}
.bz{
	height: 120rpx;
	padding: 20rpx 40rpx;
	border: 1px solid #d9d9d9;
	margin-bottom: 50rpx;
	textarea{
		height: 120rpx;
	}
}
.tj{
	padding: 0 10rpx;
	button{
		background-color: #118EE9;
		color: white;
	}
}
</style>
